package service

import (
	"content-sharing_0929/config"
	"content-sharing_0929/internal/model"
	"fmt"
	"github.com/Baidu-AIP/golang-sdk/aip/censor"
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

func SharingReview(c *gin.Context) {
	var sharing model.Sharing
	status, err := sharing.FindSharingStatus()
	if err != nil {
		return
	}

	ysh := config.Conf.BaiDuYSH
	client := censor.NewClient(ysh.API, ysh.Secret)

	for _, s := range status {

		res := client.TextCensor(s.Content)
		fmt.Println(res)
		if !strings.Contains(`"conclusion":"合规"`, res) {
			c.JSON(http.StatusBadRequest, gin.H{
				"code":    100000,
				"message": "内容不合规",
				"data":    "",
			})
			return

		}

		s.Status = 2 //审核通过默认私密
		err = s.UpdateSharing()
		if err != nil {
			return
		}

		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusOK,
			"message": "审核通过",
			"data":    "",
		})
	}

}
